package util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import bean.Gender;

/**
 * Class that validates the parameters
 * @author Anne Lorayne
 *
 */
public class ValidadorString {

	/**
	 * Checks the validity of a string
	 * @param parameter
	 * @return true, if invalid;
	 * 		   false, otherwise
	 */
	public static boolean verifyString(String parameter) {

		if (verifyInvalid(parameter))
			return false;

		for (int index = 0; index < parameter.length(); index++) {
			if (!Character.isLetter(parameter.charAt(index))
					|| !Character.isWhitespace(parameter.charAt(index)))
				return false;
			else if (Character.isWhitespace(parameter.charAt(index))) {
				if (!Character.isLetter(parameter.charAt(index + 1)))
					return false;
			}
		}
		return true;

	}

	/**
	 * Checks the parameter is a valid email 
	 * @param email
	 * @return true, if valid;
	 * 		   false, otherwise
	 */
	public static boolean verifyEmail(String email) {
		if (verifyInvalid(email))
			return false;
		String expression = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
		CharSequence emailSeq = email;
		Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(emailSeq);
		return matcher.matches();
	}

	/**
	 * Checks the parameter is a valid gender
	 * @param gender
	 * @return true, if valid;
	 * 		   false, otherwise
	 */
	public static boolean verifyGender(String gender) {
		if (verifyInvalid(gender))
			return false;
		else if (Gender.FEMALE.getName().equals(gender)
				|| Gender.MALE.getName().equals(gender)
				|| Gender.NOT_INFORMED.getName().equals(gender))
			return true;
		else return false;

	}

	/**
	 * Checks if it is empty, null and only with space
	 * @param arg
	 * @return true, if invalid;
	 * 		   false, otherwise
	 */
	public static boolean verifyInvalid(String arg) {
		if (arg.isEmpty() || arg == null || arg.trim().isEmpty())
			return true;
		return false;
	}
	public static void main(String[] args) {
		String gender = "Feminino";
		System.out.println();
		Gender[] test = Gender.values();
		System.out.println(test[0].getName());
		System.out.println(verifyGender(gender));
	}
	
	public static boolean verifyUserID(String userID) {
		// TODO Auto-generated method stub
		return false;
	}

	public static boolean verifySessionId(String sessionId) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public static boolean verifyPostID(String postID){
		return false;
	}
	
}
